package com.cz.video.common.storage.dto;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.HashMap;
import java.util.Map;

/**
 * 获取OSS上传文件授权返回结果
 */

@Data
@Schema(title = "OSS上传文件授权")
@Accessors(chain = true)
public class OssUploadAuth {

    @Schema(title = "用户表单上传的策略",description = "经过base64编码过的字符串")
    private String policy;

    @Schema(title = "对policy签名后的字符串")
    private String signature;

    @Schema(title = "访问id")
    @JsonProperty("OSSAccessKeyId")
    private String accessKeyId;

    @Schema(title = "上传文件名")
    private String key;

    @Schema(title = "oss对外服务的访问域名")
    private String host;

    @Schema(title = "过期时间")
    private long expire;

    @Schema(title = "回调信息")
    private String callback;

    @Schema(title = "自定义回调信息")
    private Map<String,Object> varCallback;

    @Schema(title = "oss服务提供商")
    private String service;

    @JsonAnyGetter
    public Map<String, Object> getVarCallback() {
        return varCallback;
    }

    @JsonAnySetter
    public void setVarCallback(String key, Object value) {
        if (varCallback == null) {
            varCallback = new HashMap<>();
        }
        varCallback.put("x:"+key, value);
    }
}

